package generateFile;

import entity.Record;
import service.LendService;
import service.impl.LendServiceImpl;
import util.DataSourceUtil;

import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

public class RecordsFile {

    public static void generateRecordList(){
        LendService lendService=new LendServiceImpl();
        List<Record> records=lendService.queryAllLend();
        FileWriter out=null;
        try {
            out=new FileWriter("D:\\Documents\\Desktop\\材料\\IDEA_workspace\\webLibrarySystem\\fileList\\借阅名单.txt");
            out.write("用户ID\t\t\t");
            out.write("书籍ID\t\t\t");
            out.write("借阅时间\t\t\t\t\t");
            out.write("归还时间\n");
            for(Record record:records){
                out.write(record.getUserId()+"\t\t");
                out.write(record.getBookId()+"\t\t");
                out.write(record.getBorrowDate()+"\t\t");
                out.write(record.getReturnDate()+"\n");
            }
            out.flush();
            System.out.println("借阅记录名单生成！");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

//    public static void main(String[] args) {
////        RecordsFile.generateRecordList();
//    }
}
